package com.example.demo.rabbitmq;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
@Component
public class Sender {
//    @Autowired
//    private AmqpTemplate rabbitmqTemplate;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(){
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId("123131323131");
//        String content = "hello" + new Date();
//        System.out.println("Sender:" +content);
        this.rabbitTemplate.convertAndSend("order-exchange",//ecxhange
                "order.abc",  // routingkey
                "123qeqweqweqweqwe",                  // 消息体
                correlationData);         // correlationData 消息唯一id
        // 发送消息
        //this.rabbitmqTemplate.convertAndSend("hello", content);
    }
}
